<?php

    function delete_cip_from_database($cip_id) {
        if ($cip_id)     tep_db_query("DELETE FROM ".TABLE_CONTRIB_INSTALLER_TAGS." WHERE cip_id=".$cip_id);
    }

    function save_tag_to_database($t_array, $cip_id, $tag_name) {
        if ($cip_id && $t_array[0]) {
            for($loop_index = 0; $loop_index < count($t_array) - 1; $loop_index++) {
                $data=array('cip_id'=>$cip_id, 'tag_id'=>$loop_index+1, 'tag_name'=>$tag_name);

                //addfile, findreplace, addcode, del_file:
                if ($t_array[$loop_index]['FILE']['@']['NAME'])    $data['file_name']=$t_array[$loop_index]['FILE']['@']['NAME'];
                //findreplace, addcode:
                if ($t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['START'])    $data['start']=$t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['START'];
                if ($t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['END'])    $data['end']=$t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['END'];
                if ($t_array[$loop_index]['FIND']['#'])
                    //$data['find']=tep_db_input(linebreak_fixing($t_array[$loop_index]['FIND']['#']));
                    $data['find']= htmlspecialchars(tep_db_input($t_array[$loop_index]['FIND']['#']));
                //findreplace:
                if ($t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['TYPE'])
                    $data['type']=$t_array[$loop_index]['ORIGINALLINENUMBERS']['@']['TYPE'];
                if (linebreak_fixing($t_array[$loop_index]['REPLACE']['#']))
                    $data['replace']=tep_db_input(linebreak_fixing($t_array[$loop_index]['REPLACE']['#']));
                 //addcode:
                if ($t_array[$loop_index]['ADD']['#'])
                    $data['add']= htmlspecialchars(tep_db_input($t_array[$loop_index]['ADD']['#']));
                 //php:
                if ($t_array[$loop_index]['INSTALL']['#'])
                    $data['install']=tep_db_input($t_array[$loop_index]['INSTALL']['#']);
                if ($t_array[$loop_index]['REMOVE']['#'])
                    $data['remove']=tep_db_input($t_array[$loop_index]['REMOVE']['#']);
                //make_dir
                if ($t_array[$loop_index]['PARENT_DIR']['@']['NAME'])    $data['parent_dir_name']=$t_array[$loop_index]['PARENT_DIR']['@']['NAME'];
                if ($t_array[$loop_index]['DIR']['@']['NAME'])    $data['dir_name']=$t_array[$loop_index]['DIR']['@']['NAME'];
                 //sql
                if ($t_array[$loop_index]['QUERY']['#'])
                    $data['query']=tep_db_input($t_array[$loop_index]['QUERY']['#']);
                if ($t_array[$loop_index]['REMOVE_QUERY']['#'])
                    $data['remove_query']=tep_db_input($t_array[$loop_index]['REMOVE_QUERY']['#']);
                //addcode, findreplace
                if ($t_array[$loop_index]['@']['TYPE'])    $data['code_type']=$t_array[$loop_index]['@']['TYPE'];
                //if ()    $data['type']=;
                echo_array($data);
                //var_dump($data);
                tep_db_perform(TABLE_CONTRIB_INSTALLER_TAGS, $data);
            }
        }
    }

?>